home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / GEN_STRI.H < prev    next >
Text File  |  1992-08-19  |  25KB  |  593 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. //
  13. // Created: MBN 03/17/89 -- Initial design and implementation
  14. // Updated: MBN 04/06/89 -- Performance enhancement by changing several
  15. //                          methods and friends to inline, and addition
  16. //                          of two private friend functions.
  17. // Updated: MBN 06/07/89 -- Added growth ratio slot and resize method
  18. // Updated: MBN 06/30/89 -- Created Gen_String class with regular expression
  19. // Updated: DKM 07/07/89 -- To work around Xenix 31 char limit:
  20. //                          Shortened is_less_than        to is_lt
  21. //                                    is_greater_than     to is_gt
  22. //                                    is_less_or_equal    to is_le
  23. //                                    is_greater_or_equal to is_ge
  24. //                          Removed is_equal_or_less and is_greater_or_less
  25. // Updated: LGO 08/09/89 -- Inherit from Generic
  26. // Updated: MBN 09/07/89 -- Added conditional exception handling
  27. // Updated: LGO 10/28/89 -- Removed is_lt, is_gt, is_le, is_ge, is_equal
  28. //                          and is_not_equal (use char* functions instead)
  29. // Updated: LGO 11/07/89 -- Removed strcmp, strncmp
  30. // Updated: LGO 11/07/89 -- Make check_memory strcpy and operator=
  31. //                          take const arguments
  32. // Updated: MBN 12/15/89 -- Sprinkled "const" qualifier all over the place!
  33. // Updated: MBN 01/02/90 -- Made find search for the first/next regexp match 
  34. // Updated: LGO 01/05/90 -- Removed strchr, strrchr
  35. // Updated: MJF 05/21/90 -- Moved delete from grow_memory to validate
  36. // Updated: MJF 06/15/90 -- Added inline strncpy(...,int) to remove ambiguity
  37. // Updated: DLS 03/22/91 -- New lite version
  38. // Updated: JAM 08/14/92 -- removed DOS specifics, stdized #includes
  39. // Updated: JAM 08/14/92 -- defined set_growth_ratio as inline (prob. typo)
  40. //
  41. // The   Gen_String class   provides   dynamic,  efficient strings   for  a C++
  42. // application programmer  with support for   reference counting, delayed copy,
  43. // and  regular expression   pattern   matching/replacment.  The  private  data
  44. // consists of a pointer to a structure of type String_Layout.   This structure
  45. // is defined for use by the Gen_String class and  is public so that Gen_String
  46. // constructors can  allocate correct   memory.  In addition, the  private data
  47. // section contains a slot that maintains the length of the string (ie.  number
  48. // of characters) and a pointer to the first character of the string.  Finally,
  49. // a static for the entire Gen_String class  contains the allocation size to be
  50. // used   when an  Gen_String object  needs  to grow  dynamically.   This has a
  51. // default value that may be over-ridden  by the  user when the  constructor is
  52. // invoked.
  53. //
  54. // The string layout structure has several fields.  The size variable maintains
  55. // the actual  number of bytes allocated  to this string  object char* pointer.
  56. // This may be different to the length slot in the Gen_String object due to the
  57. // dynamic nature  of the  string  object  and/or  sub-string  operations.  The
  58. // reference count variable  maintains  a  count  of  the number  of Gen_String
  59. // pointers  that point  to  this  actual string.  This  is  utilized to reduce
  60. // copying of  string objects  at   assignment, for example.   This  scheme  is
  61. // similar to that used  in a virtual  memory management  system when a  parent
  62. // process spawns a child process.  The  child process  inherits a copy  of the
  63. // parents memory,  but  instead  of   copying,  a pointer  to these  pages,  a
  64. // reference count is  kept.  If the child process  only reads a page, it never
  65. // needs to be copied.  Only  when a change is  made  must a copy actually take
  66. // place.   In  general, this  scheme drastically  cuts   down byte  copies and
  67. // improves runtime efficieny.   The following diagram  displays two Gen_String
  68. // objects that share a char* string.   Note  that the Gen_String2 object is in
  69. // fact a sub-string of Gen_String1.
  70. // 
  71. //  +----------->-------------+
  72. //  |                         |
  73. //  |         Gen_String1     V          Virtual Function Table
  74. //  |        +-----------+    |                +----------+
  75. //  |        |  V_Table--+----+------------->  :Alloc_Size:
  76. //  |        +-----------+                     :  ....    :
  77. //  |        | Length=16 |                     :  ....    :       +----------+
  78. //  |        +-----------+                     +----------+       |  Regular |
  79. //  |        |  *rgexp --+--------------------------------------->|Expression|
  80. //  |        +-----------+                                        |  Object  |
  81. //  |        |rgexp_index|                                        +----------+
  82. //  |        +-----------+
  83. //  ^        |    p    --+---+
  84. //  |        +-----------+   |
  85. //  |        |   str   --+---)-------------->-------------+
  86. //  |        +-----------+   |                            |
  87. //  |                        |                            |
  88. //  |                        |                            |
  89. //  |     Gen_String2        |        Layout_Struct       |
  90. //  |    +-----------+       +------->+-----------+       |
  91. //  +----+--V_Table  |       |        | Ref_Cnt=2 |       |
  92. //       +-----------+       |        +-----------+       |
  93. //       | Length=6  |       |        |  Size=25  |       V
  94. //       +-----------+       |        +-----------+      +--------------------+
  95. //    +--+-- *rgexp  |       |        | str_start-+----->|This is a string    |
  96. //    |  +-----------+       |        +-----------+      +--------------------+
  97. //    |  |rgexp_index|       |                                      ^
  98. //    |  +-----------+       |                                      |
  99. //    |  |    p    --+-------+                                      |
  100. //    |  +-----------+                                              |
  101. //    |  |   str   --+--------------------->------------------------+
  102. //    |  +-----------+   
  103. //    |                  +----------+
  104. //    |                  |  Regular |
  105. //    +----------------->|Expression|
  106. //                       |  Object  |
  107. //                       +----------+
  108. //
  109. // There are  several   constructors  for this   class.  The empty  constructor
  110. // initializes an Gen_String object  and allocates the  layout structure with a
  111. // default allocation of  MEM_BLK_SZ bytes for  the char* pointer.   The second
  112. // constructor takes a char* argument and provides for the initialization of an
  113. // Gen_String object  to a single character or  character  string.    The third
  114. // constructor provides  initialization  of an   Gen_String  Object to that  of
  115. // another Gen_String  object.  Finally,  the two  constructors with an integer
  116. // argument allow  the user  to initialize  a  Gen_String object with either  a
  117. // char* or another Gen_String object and specify the initial memory allocation
  118. // size for the char* pointer.  This is useful  for a user  who expect a String
  119. // object to be fairly dynamic; allocating  a  larger chunk initially cuts down
  120. // on the number of new() requests needed to grow the object later.
  121. //
  122. // The standard  ANSI "str____" function names are  all overloaded for use with
  123. // both  char*  and  String   objects.  Operators  for  String   concatenation,
  124. // assignment, and  comparison are also provided.   In addition,  functions for
  125. // case conversion and string token trimming are provided.   Finally, note that
  126. // the operator functions use corresponding functions with the  "case" flag set
  127. // to SENSITIVE.  A user  can perform case-INSENSITIVE operations by explicitly
  128. // calling the appropriate function.
  129. //
  130. // Envelope is not needed, because the Gen_Strings already share the
  131. // same layout structure, and that copy constructor, only copy pointers, and
  132. // increment ref_count.
  133.  
  134. #ifndef GEN_STRINGH                // If no Gen_String class
  135. #define GEN_STRINGH                // Include the header file
  136.  
  137. #ifndef CHARH                    // If extended char* not here
  138. #include <cool/char.h>
  139. #endif
  140.  
  141. #ifndef REGEXPH                    // If no regular expressions
  142. #include <cool/Regexp.h>            // Include definition
  143. #endif
  144.  
  145. #include <stdlib.h>        // Include standard c library support
  146.  
  147. #define MEM_BLK_SZ 100
  148.  
  149. struct String_Layout {                // Internal layout structure 
  150.   long size;                    // Bytes allocated
  151.   short ref_count;                // Pointers to other Gen_String
  152.   char* start;                    // Pointer to start of string
  153. };
  154.  
  155. class CoolGen_String {
  156. public:
  157.   CoolGen_String ();                   // CoolGen_String x;
  158.   CoolGen_String (char);               // CoolGen_String x = 'A';
  159.   CoolGen_String (const char*);               // CoolGen_String x = "ABCDEFG";
  160.   CoolGen_String (const CoolGen_String&);      // Copy constructor
  161.   CoolGen_String (const CoolGen_String&, long);    // CoolGen_String x = y; memory size
  162.   CoolGen_String (const char*, long);           // CoolGen_String x = "AB"; mem size
  163.   
  164.   ~CoolGen_String();                   // Destructor for CoolGen_String
  165.  
  166.   Boolean insert (const char*, long);           // Insert chars at index
  167.   Boolean remove (long, long);               // Remove chars between indexes
  168.   Boolean replace (const char*, long, long);   // Replace chars between indexes
  169.  
  170.   void yank (CoolGen_String&, long, long);    // Delete and set the given 
  171.                                                // CoolGen_String to the characters
  172.                                                // at index
  173.  
  174.   void sub_string (CoolGen_String&, long, long);   // Set the given Gen_String to 
  175.                                                // the chars between indexes
  176.  
  177.   friend CoolGen_String& strncpy (CoolGen_String&, const char*, long);// Copy "n" chars
  178.   /*##inline*/ friend CoolGen_String& strncpy (CoolGen_String&, const char*, int);
  179.  
  180.   friend ostream& operator<< (ostream&, const CoolGen_String&);
  181.   /*##inline*/ friend ostream& operator<< (ostream&, const CoolGen_String*);
  182.   
  183.   inline CoolGen_String& operator= (char);    // x = 'A';
  184.   inline CoolGen_String& operator= (const char*); // x = "ABCDEFG";
  185.   inline CoolGen_String& operator= (const CoolGen_String&); // x = y;
  186.   
  187.   inline CoolGen_String& operator+= (char);    // Concat with assignment 
  188.   inline CoolGen_String& operator+= (const char*);
  189.   inline CoolGen_String& operator+= (const CoolGen_String&);
  190.   
  191.   /*##inline*/ friend CoolGen_String operator+ (const CoolGen_String&, char);
  192.   /*##inline*/ friend CoolGen_String operator+ (const CoolGen_String&, const char*);
  193.   /*##inline*/ friend CoolGen_String operator+ (const CoolGen_String&, const CoolGen_String&);
  194.   
  195.   inline operator const char*() const;        // Convert Gen_String to const char*
  196.   void compile (const char*);            // Compile regexp in argument
  197.   Boolean find ();                // Search for first/next regexp
  198.   inline long start ();                // Return start index of match
  199.   inline long end ();                // Return end index of match
  200.   inline Boolean is_valid ();            // TRUE/FALSE validates regexp
  201.   
  202.   void reverse ();                // Reverse character order
  203.   void clear ();                // Reset NULL terminator
  204.   void resize (long);                // Allocate at least min size
  205.   inline char& operator[] (long i);        // x[4] --> fifth character
  206.  
  207.   inline long capacity() const;            // Returns maximum size string 
  208.   inline void set_alloc_size (int);        // Set memory block alloc size
  209.   inline void set_growth_ratio (float);        // Set growth percentage
  210.   
  211.   inline Boolean operator== (const CoolGen_String&) const;     
  212.   inline Boolean operator== (const char*) const;          
  213.   
  214.   inline Boolean operator!= (const CoolGen_String&) const;     
  215.   inline Boolean operator!= (const char*) const;          
  216.   
  217.   inline Boolean operator< (const CoolGen_String&) const;      
  218.   inline Boolean operator< (const char*) const;          
  219.   
  220.   inline Boolean operator> (const CoolGen_String&) const;      
  221.   inline Boolean operator> (const char*) const;    
  222.   
  223.   inline Boolean operator<= (const CoolGen_String&) const;     
  224.   inline Boolean operator<= (const char*) const;    
  225.   
  226.   inline Boolean operator>= (const CoolGen_String&) const;     
  227.   inline Boolean operator>= (const char*) const;    
  228.   
  229.   /*##inline*/ friend long strlen (const CoolGen_String&); // Return length of string
  230.   
  231.   friend CoolGen_String& strcat (CoolGen_String&, const CoolGen_String&);
  232.   friend CoolGen_String& strcat (CoolGen_String&, const char*);
  233.   friend CoolGen_String& strcat (CoolGen_String&, char);
  234.   
  235.   friend CoolGen_String& strncat (CoolGen_String&, const CoolGen_String&, int);
  236.   friend CoolGen_String& strncat (CoolGen_String&, const char*, int);
  237.   
  238.   friend CoolGen_String& strcpy (CoolGen_String&, char);
  239.   friend CoolGen_String& strcpy (CoolGen_String&, const char*);
  240.   friend CoolGen_String& strcpy (CoolGen_String&, const CoolGen_String&); 
  241.   
  242.   friend long strtol(const CoolGen_String&, char** ptr=NULL, int radix=10);
  243.   friend long atol (const CoolGen_String&);          
  244.   friend int atoi (const CoolGen_String&);    
  245.   
  246.   friend double strtod (const CoolGen_String&, char** ptr=NULL);
  247.   /*##inline*/ friend double atof (const CoolGen_String&);
  248.   
  249.   friend CoolGen_String& trim (CoolGen_String&, const char*);
  250.   friend CoolGen_String& left_trim (CoolGen_String&, const char*); 
  251.   friend CoolGen_String& right_trim (CoolGen_String&, const char*);
  252.   
  253.   friend CoolGen_String& upcase (CoolGen_String&);
  254.   friend CoolGen_String& downcase (CoolGen_String&);
  255.   friend CoolGen_String& capitalize (CoolGen_String&);
  256.  
  257. private:
  258.   long length;                       // Number of characters 
  259.   char* str;                       // Pointer to string
  260.   String_Layout *p;                   // Pointer to layout structure
  261.   float growth_ratio;                   // If non-zero, grow by this %
  262.   static int alloc_size_s;               // Memory allocation growth size
  263.   CoolRegexp* rgexp;                   // Pointer to regular expression
  264.   long rgexp_index;                   // Start index for regexp search
  265.  
  266.   void bracket_error (long);            // Raise exception
  267.   void ratio_error (float);            // Raise exception
  268.   void find_error ();                // Raise exception
  269.   void size_error (int);            // Raise exception
  270.   
  271.   void validate(Boolean dont_copy=FALSE);    // check ref_count and memory
  272.   void update_ref_count();            // Don't share string
  273.   void grow_memory (Boolean dont_copy);        // Grow string
  274. };
  275.  
  276. // operator<< -- Overload output operator for CoolGen_String objects
  277. // Input:        CoolGen_String pointer
  278. // Output:       Formatted output and stream descriptor
  279.  
  280. inline ostream& operator<< (ostream& os, const CoolGen_String* s) {
  281.   return os << s->str;                
  282. }
  283.  
  284. // operator[] -- Return a single character element from string
  285. // Input:        this*, index "i"
  286. // Output:       The "ith-1" character from String
  287.  
  288. inline char& CoolGen_String::operator[] (long i) {
  289. #if ERROR_CHECKING
  290.   if (i >= this->length)            // If index out of range
  291.     this->bracket_error (i);            // Raise exception
  292. #endif
  293.   return (this->str[i]);
  294. }
  295.  
  296.  
  297. // capacity -- Determine the maximum size string possible with growing
  298. // Input:      None
  299. // Output:     Maximum number of characters before growth is required
  300.  
  301. inline long CoolGen_String::capacity() const {
  302.   return (this->p->size-1);            
  303. }
  304.  
  305.  
  306. // set_alloc_size -- Set the default allocation size growth rate
  307. // Input:            Growth size in number of elements
  308. // Output:           None
  309.  
  310. inline void CoolGen_String::set_alloc_size (int n) {
  311. #if ERROR_CHECKING
  312.   if (n < 0)                    // If negative growth size
  313.     this->size_error (n);            // Raise exception
  314. #endif
  315.   this->alloc_size_s = n;            // Set growth size
  316. }
  317.  
  318.  
  319. // set_growth_ratio -- Set the growth percentage for this instance of String
  320. // Input:              Percentage growth rat
  321. // Output:             None
  322.  
  323. inline void CoolGen_String::set_growth_ratio (float ratio) {
  324. #if ERROR_CHECKING
  325.   if (ratio <= 0.0)                // If positive growth factor
  326.     this->ratio_error (ratio);            // Raise exception
  327. #endif
  328.   this->growth_ratio = ratio;            // Set growth size
  329. }
  330.  
  331.  
  332. // operator const char* -- Provide an accessor to the character pointer
  333. // Input:            this* 
  334. // Output:           this->str character pointer
  335. inline CoolGen_String::operator const char*() const {
  336.   return (this->str);
  337. }
  338.  
  339. // start -- Return the zero-relative start index of regular expression match
  340. // Input:   None
  341. // Output:  Start index into string
  342.  
  343. inline long CoolGen_String::start () {
  344.   return (this->rgexp_index + this->rgexp->start ());
  345. }
  346.  
  347.  
  348. // End -- Return the zero-relative end index of the regular expression match
  349. // Input:   None
  350. // Output:  End index into string
  351.  
  352. inline long CoolGen_String::end () {
  353.   return (this->rgexp_index + this->rgexp->end ());
  354. }
  355.  
  356.  
  357. // is_valid -- Returns the validity of the regular expression
  358. // Input:      None
  359. // Output:     TRUE/FALSE
  360.  
  361. inline Boolean CoolGen_String::is_valid () {
  362.   return (this->rgexp != NULL) &&         // If a Regexp object
  363.          this->rgexp->is_valid ();        // return Regexp status
  364. }
  365.  
  366.  
  367. // operator= -- Assignment to a single character: x = 'A';
  368. // Input:       Single character
  369. // Output:      CoolGen_String object containing character string
  370.  
  371. inline CoolGen_String& CoolGen_String::operator= (char c) {
  372.   return (strcpy (*this, c));            
  373. }
  374.  
  375.  
  376. // operator= -- Assignment to a character string: x = "ABCDEFG";
  377. // Input:       Character string
  378. // Output:      CoolGen_String object containing character string
  379.  
  380. inline CoolGen_String& CoolGen_String::operator= (const char* c) {
  381.   return (strcpy (*this, c));            
  382. }
  383.  
  384.  
  385. // operator= -- Assignment to another CoolGen_String: x = y;
  386. // Input:       Reference to CoolGen_String object
  387. // Output:      CoolGen_String object sharing memory with other CoolGen_String
  388.  
  389. inline CoolGen_String& CoolGen_String::operator= (const CoolGen_String& s) {
  390.   return (strcpy (*this, s));            
  391. }
  392.  
  393.  
  394. // operator+= -- Concatenation of a character: x += 'A';
  395. // Input:        Character
  396. // Output:       CoolGen_String object concatenated with character
  397.  
  398. inline CoolGen_String& CoolGen_String::operator+= (char c) {
  399.   return (strcat (*this, c));            
  400. }
  401.  
  402. // operator+ -- String concatenation of a character: y = x + 'A';
  403. // Input:       Character
  404. // Output:      new CoolGen_String object concatenated with character
  405.  
  406. inline CoolGen_String operator+ (const CoolGen_String& s, char c) {
  407.   CoolGen_String temp(s);            // temporary copy of s
  408.   temp += c;                    // mutate temp with += c
  409.   return temp;                    // return new copy by value
  410. }
  411.  
  412. // operator+= -- Concatenation of a character string: x += "ABCDEFG";
  413. // Input:        Character string
  414. // Output:       CoolGen_String object concatenated with character string
  415.  
  416. inline CoolGen_String& CoolGen_String::operator+= (const char* c) {
  417.   return (strcat (*this, c));            
  418. }
  419.  
  420.  
  421. // operator+ -- String concatenation of a character string: y = x + "ABCDEFG";
  422. // Input:       Character string
  423. // Output:      new CoolGen_String object concatenated with character string
  424.  
  425. inline CoolGen_String operator+ (const CoolGen_String& s, const char* c) {
  426.   CoolGen_String temp(s);            // temporary copy of s
  427.   temp += c;                    // mutate temp with += c
  428.   return temp;                    // return new copy by value
  429. }
  430.  
  431.  
  432. // operator+= -- Concatenation of another CoolGen_String: x += y;
  433. // Input:        CoolGen_String reference
  434. // Output:       CoolGen_String object concatenated with CoolGen_String contents
  435.  
  436. inline CoolGen_String& CoolGen_String::operator+= (const CoolGen_String& s) {
  437.   return (strcat (*this, s));            
  438. }
  439.  
  440. // operator+ -- String concatenation of another string: z = x + y;
  441. // Input:       CoolGen_String reference
  442. // Output:      CoolGen_String object concatenated with String contents
  443.  
  444. inline CoolGen_String operator+ (const CoolGen_String& s1, const CoolGen_String& s2) {
  445.   CoolGen_String temp(s1);            // temporary copy of s1
  446.   temp += s2;                    // mutate temp with += s2
  447.   return temp;                    // return new copy by value
  448. }
  449.  
  450.  
  451.  
  452. // operator== -- Test for equality of two CoolGen_String objects
  453. // Input:        this*, CoolGen_String reference
  454. // Output:       Boolean TRUE/FALSE
  455.  
  456. inline Boolean CoolGen_String::operator== (const CoolGen_String& s) const{
  457.   return (is_equal (this->str, s.str, SENSITIVE));
  458. }
  459.  
  460.  
  461. // operator== -- Test for equality of an CoolGen_String and char*
  462. // Input:        this*, char* pointer
  463. // Output:       Boolean TRUE/FALSE
  464.  
  465. inline Boolean CoolGen_String::operator== (const char* c) const {
  466.   return (is_equal (this->str, c, SENSITIVE));
  467. }
  468.  
  469.  
  470. // operator!= -- Test for inequality of two CoolGen_String objects
  471. // Input:        this*, CoolGen_String reference
  472. // Output:       Boolean TRUE/FALSE
  473.  
  474. inline Boolean CoolGen_String::operator!= (const CoolGen_String& s) const {
  475.   return (is_not_equal (this->str, s.str, SENSITIVE));
  476. }
  477.  
  478.  
  479. // operator!= -- Test for inequality of two CoolGen_String objects
  480. // Input:        this*, char* pointer
  481. // Output:       Boolean TRUE/FALSE
  482.  
  483. inline Boolean CoolGen_String::operator!= (const char* c) const {
  484.   return (is_not_equal (this->str, c, SENSITIVE));
  485. }
  486.  
  487.  
  488. // operator< -- Test for lexical ordering before a CoolGen_String
  489. // Input:       this*, CoolGen_String reference
  490. // Output:      Boolean TRUE/FALSE
  491.  
  492. inline Boolean CoolGen_String::operator< (const CoolGen_String& s) const {
  493.   return (is_lt (this->str, s.str, SENSITIVE));
  494. }
  495.  
  496.  
  497. // operator< -- Test for lexical ordering before a CoolGen_String
  498. // Input:       this*, char* pointer
  499. // Output:      Boolean TRUE/FALSE
  500.  
  501. inline Boolean CoolGen_String::operator< (const char* c) const {
  502.   return (is_lt (this->str, c, SENSITIVE));
  503. }
  504.  
  505.  
  506. // operator> -- Test for lexical ordering after a CoolGen_String
  507. // Input:       this*, CoolGen_String reference
  508. // Output:      Boolean TRUE/FALSE
  509.  
  510. inline Boolean CoolGen_String::operator> (const CoolGen_String& s) const {
  511.   return (is_gt (this->str, s.str, SENSITIVE));
  512. }
  513.  
  514.  
  515. // operator> -- Test for lexical ordering after a CoolGen_String
  516. // Input:       this*, char* pointer
  517. // Output:      Boolean TRUE/FALSE
  518.  
  519. inline Boolean CoolGen_String::operator> (const char* c) const {
  520.   return (is_gt (this->str, c, SENSITIVE));
  521. }
  522.  
  523.  
  524. // operator<= -- Test for lexical ordering before or equal to a CoolGen_String
  525. // Input:        this*, CoolGen_String reference
  526. // Output:       Boolean TRUE/FALSE
  527.  
  528. inline Boolean CoolGen_String::operator<= (const CoolGen_String& s) const {
  529.   return (is_le (this->str, s.str, SENSITIVE));
  530. }
  531.  
  532.  
  533. // operator<= -- Test for lexical ordering before or equal to a CoolGen_String
  534. // Input:        this*, char* pointer
  535. // Output:       Boolean TRUE/FALSE
  536.  
  537. inline Boolean CoolGen_String::operator<= (const char* c) const {
  538.   return (is_le (this->str, c, SENSITIVE));
  539. }
  540.  
  541.  
  542. // operator>= -- Test for lexical ordering after or equal to a CoolGen_String
  543. // Input:        this*, String reference
  544. // Output:       Boolean TRUE/FALSE
  545.  
  546. inline Boolean CoolGen_String::operator>= (const CoolGen_String& s) const {
  547.   return (is_ge (this->str, s.str, SENSITIVE));
  548. }
  549.  
  550.  
  551. // operator>= -- Test for lexical ordering after or equal to a CoolGen_String
  552. // Input:        this*, char* pointer
  553. // Output:       Boolean TRUE/FALSE
  554.  
  555. inline Boolean CoolGen_String::operator>= (const char* c) const {
  556.   return (is_ge (this->str, c, SENSITIVE));
  557. }
  558.  
  559.  
  560.  
  561.  
  562. // strlen -- Return the number of characters in the string
  563. // Input:    CoolGen_String reference
  564. // Output:   Length of the string
  565.  
  566. inline long strlen (const CoolGen_String& s) {
  567.   return (s.length);
  568. }
  569.  
  570.  
  571. // atof -- Equivalent to strtod (str, (char**)END_OF_STRING)
  572. // Input:  Reference to CoolGen_String object
  573. // Output: Double representing value contained in string
  574.  
  575. inline double atof (const CoolGen_String& s) {
  576.   return (strtod ((char *)s.str, (char **) END_OF_STRING));
  577. }
  578.  
  579.  
  580. // strncpy -- Returns s, with the first length characters of source copied
  581. //            into it.  The old value of s is lost.
  582. // Input   -- A reference to a CoolGen_String s, a char* source, and an int length.
  583. // Output  -- The modified CoolGen_String s.
  584.  
  585. inline CoolGen_String& strncpy(CoolGen_String& s, const char* source, int n) {
  586.   return strncpy(s, source, (long) n);
  587. }
  588.  
  589.  
  590. #endif                        // End of GEN_STRINGH
  591.  
  592.  
  593.